/**
 * 解决toJSON不是vue实例中方法的问题
 * @returns {string}
 */
export const toJSON = () => {
	return JSON.stringify(this)
}

/**
 * 获取今天的日期
 */
export const getTodayDate = () => {
	let date = new Date();
	let year = date.getFullYear(); //获取完整的年份(4位)
	let month = (date.getMonth() + 1).toString(); //获取当前月份(0-11,0代表1月)
	month = month.length === 1 ? "0" + month : month
	let day = date.getDate().toString(); //获取当前日(1-31)
	day = day.length === 1 ? "0" + day : day
	return `${year}-${month}-${day}`;
}

/**
 * 获取明天的日期
 * @returns {string}
 */
export const getTomorrow = () => {
	let date = new Date();
	date.setTime(date.getTime() + 24 * 60 * 60 * 1000); //加上一天的秒数
	let tomorrow = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
	return tomorrow;
}

/**
 * 格式化指定时间对象
 * @param dateObj 时间对象
 * @returns {string}
 */
export const formatDate = dateObj => {
	let year = dateObj.getFullYear();
	let month = (dateObj.getMonth() + 1) + "";
	let day = dateObj.getDate() + "";
	let hour = dateObj.getHours() + "";
	let minute = dateObj.getMinutes() + "";
	let second = dateObj.getSeconds() + "";
	if (month.length === 1) month = '0' + month;
	if (day.length === 1) day = '0' + day;
	if (hour.length === 1) hour = '0' + hour;
	if (minute.length === 1) minute = '0' + minute;
	if (second.length === 1) second = '0' + second;
	return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
}